/*
 * Copyright (c) 2020, 2023, keyila All rights reserved.
 *
 */
package com.clp.study.designPattern.strategyPattern.demo;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author clp
 * @version 1.0
 */
@Component
public class PayFactory implements InitializingBean {

    @Resource
    private List<PayHandler> payHandlerList;

    private Map<PayChannelEnum,PayHandler> handlerMap=new HashMap<>();


    @Override
    public void afterPropertiesSet() throws Exception {
        for (PayHandler payHandler: payHandlerList){
            handlerMap.put(payHandler.getChannel(),payHandler);
        }
    }

    public PayHandler getHandlerByCode(int code){
        PayChannelEnum payChannelEnum=PayChannelEnum.getByCode(code);
        return handlerMap.get(payChannelEnum);
    }
}
